<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h1>0</h1>
<h2>0</h2>

<input type="button" value="停止定时器" onclick="clears()">



<script>
    let cont = 0;
    let shi = 0;
    let h1 = document.querySelector("h1");
    // 开启定时器每隔一秒调用一次方法
    //方法作为参数进行传递时不写()
    setInterval(f,1000);
    function f() {
        cont++;
        let h2 = document.querySelector("h2");
        h2.innerText = cont;
        if(cont>=60){
            h1.innerText = shi+1;
            h2.innerText=0;
        }
    }

    //----------------匿名方法开启定时器------------------------------
    let number = 0;
    let timer = setInterval(function (){
        number++;
        let h2 = document.querySelector("h2");
        h2.innerText=number;
    },100)
    function clears(){
        alert(11)
        clearInterval(timer);
    }
    //-----------------只执行一次的定时器--------------------
    setTimeout(function (){
        alert("时间到啦");
    },3000)

    //alert("弹出来");
    //confirm("confirm弹出确认框   你是不是想出去完");
    //prompt("prompt弹出文本框  你瘦吗");

</script>
</body>
</html>